#!/bin/bash
###############################################################################################
#   this script compares 'output' directory's xml files with those of 'output/done' folder's,
# and delete those already exist in 'output/done' folder to avoid duplicated processing.
###############################################################################################

output_dir=$1

output_done_dir=$output_dir"/done"

echo '[info] begin to check all done files...'
i=0
fileArr=$output_dir"/*.xml"
for file in $fileArr
do
    fileName=$(basename $file)
    doneFile=$output_done_dir"/"$fileName
    if [ -e $doneFile ]
    then
#        echo "[debug] removing file $file..."
        rm -f $file
        i=$((i+1))
    fi
done
echo '*****************************************'
echo '[info] job is done!'
echo "[info] original file number: ${#fileArr}"
echo "[info] deleted file number: $i"
echo '*****************************************'
